<template>
  <div>
    <el-form ref="form" :model="app_from" label-width="120px">
      <el-form-item label="小程序appid">
        <el-input v-model="app_from.appid"></el-input>
      </el-form-item>
      <el-form-item label="代码上传秘钥">
        <el-upload
            class="upload-demo"
            drag
            action="/api/wx/applet/upload/file"
            :on-success="app_upload_success"
            multiple>
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <div class="el-upload__tip" slot="tip">只能上传.key的文件</div>
        </el-upload>
      </el-form-item>
      <el-form-item label="小程序名称">
        <el-input v-model="app_from.name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="create_app_submit">确 定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "CreateApp",
  data() {
    return {
      app_from: {
        appid: '',
        private_key_path: '',
        name: ''
      }
    }
  },
  methods: {
    create_app_submit(){
      this.$emit("create_app_submit",this.app_from)
    },
    app_upload_success(resp) {
      if (resp.code == 200) {
        this.$message({
          showClose: true,
          message: '恭喜你，文件上传成功',
          type: 'success'
        });
        this.app_from.private_key_path = resp.data.url;
      } else {
        this.$message({
          showClose: true,
          message: resp.msg,
          type: 'success'
        });
      }
    }
  }
}
</script>

<style scoped>

</style>